#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
# sys.path.append('/opt/work/caffe/python')
sys.path.insert(0, '.')

import argparse
import os
import struct
import cv2

image_path = r'/rootfs/media/kasim/Data1/data/VideoCropFace'
image_list_file = r'/rootfs/media/kasim/Data1/data/VideoCropFace/BaiduFaceAttr.txt'

SLEEP = 0
USE_RESIZE = False
DISPLAY_WIDTH = 1280
DISPLAY_HEIGHT = 720


def display_image(image_path):
    image = cv2.imread(image_path)
    if USE_RESIZE:
        if (image.shape[0] != DISPLAY_HEIGHT) or (image.shape[1] != DISPLAY_WIDTH):
            image = cv2.resize(image, (DISPLAY_WIDTH, DISPLAY_HEIGHT))
    cv2.imshow('image', image)
    if 0 == SLEEP:
        key = cv2.waitKey()
    else:
        key = cv2.waitKey(SLEEP)

    if (key == ord('q')) or (key == ord('Q')) or (key == 27):
        return False

    return True


def main():
    image_list = []
    with open(image_list_file, 'r') as file:
        for line in file.readlines():
            image_name = line.split()[0].strip()
            image_list.append(image_name)

    for image_name in image_list:
        if not display_image(os.path.join(image_path, image_name)):
            break

    print('Finish!')


if __name__ == '__main__':
    main()
